#include<iostream>
#include<string>

using namespace std;

/*
设计一个简单的学生成绩管理系统，要求使用类和函数实现以下功能：

1:定义一个 Student 类，包含学生姓名、学号和3门课程的成绩
2:实现计算每个学生平均分的成员函数
3:实现显示学生信息的成员函数
4:在主函数中创建多个学生对象并测试功能
*/

class Student{
    private:
        string name;
        string id;
        double source[3];
    public:
        Student(string n,string i,double s1, double s2, double s3){
            name = n;
            id = i;
            source[0] = s1;
            source[1] = s2;
            source[2] = s3;
        }
    // 计算平均分
    double calculateAverage() {
        // 实现平均分计算
        double sum = 0.0;
        for (int i=0; i<3; ++i) {
            sum += source[i];
        }
        return sum / 3.0;
    }

    // 显示学生信息
    void displayInfo() {
        // 实现信息显示
        cout << "学生姓名：" << name << endl;
        cout << "学生Id：" << id << endl;
        cout << "学生三门课成绩：";
        for (int i=0; i<3 ; ++i){
            cout << source[i] << " ";
        } 
        cout << endl;
    }

    
    // 获取学生姓名 用于比较函数
    string getName(){
        return name;
    }

};

// 非成员工具函数：创建学生对象
Student createStudent() {
    // 实现创建学生对象的逻辑
    string name, id;
    double s1, s2, s3;
    cout << "请输入学生姓名: ";
    cin >> name;
    cout << "请输入学号: ";
    cin >> id;
    cout << "请输入三门课成绩(用空格分隔): ";
    cin >> s1 >> s2 >> s3;
    return Student(name, id, s1, s2, s3);
}

void compareAverage(Student& s1, Student& s2){
    double avg1 = s1.calculateAverage();
    double avg2 = s2.calculateAverage();

    cout << "\n比较结果：" << endl;
    cout <<s1.getName()<< "的平均分数"<<avg1<<endl;
    cout <<s2.getName()<< "的平均分数"<<avg2<<endl;

    if(avg1 > avg2) {
        cout << s1.getName() << "的平均分更高" << endl;
    } else if(avg1 < avg2) {
        cout << s2.getName() << "的平均分更高" << endl;
    } else {
        cout << "两人的平均分相同" << endl;
    }
}

int main () {
    cout << "=== 测试1 ===" << endl;
    Student stu1("张三", "2023001", 85, 90, 78);
    stu1.displayInfo();
    cout << "平均分: " << stu1.calculateAverage() << endl;

    cout << "=== 测试2 ===" << endl;
    Student stu2 = createStudent();
    stu2.displayInfo();
    cout << "平均分: " << stu2.calculateAverage() << endl;
    
    cout << "\n----------------\n" << endl;
    
    cout << "=== 测试3 ===" << endl;
    Student stu3("李四", "2023002", 92, 88, 95);
    stu3.displayInfo();
    cout << "平均分: " << stu3.calculateAverage() << endl;
    
    cout << "\n----------------\n" << endl;

    compareAverage(stu1,stu2);
    compareAverage(stu2,stu3);
    compareAverage(stu1,stu3);
    return 1;
}